//
//  TF_kuaijinView.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2021/12/13.
//  Copyright © 2021 Talkfun. All rights reserved.
//

import UIKit

class TF_kuaijinView: UIView {

    @objc public var backgroundView:UIView!
    @objc public var kuaiImageView:UIImageView!
    @objc public var timeLabelAndTotalTimeLabel:UILabel!
    @objc public var kuaiLabel:UILabel!
  
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isUserInteractionEnabled = false
        self.backgroundView = UIView.init()
        self.backgroundView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.65)
        self.addSubview(self.backgroundView)
        
        self.kuaiImageView = UIImageView.init()
        self.kuaiImageView.image = UIImage.init(named:"快进")
        self.backgroundView.addSubview(self.kuaiImageView)
        
        self.timeLabelAndTotalTimeLabel = UILabel.init()
        self.timeLabelAndTotalTimeLabel.font = UIFont.systemFont(ofSize: 13)
        self.timeLabelAndTotalTimeLabel.textColor = UIColor.white
        self.timeLabelAndTotalTimeLabel.textAlignment = .center
        self.backgroundView.addSubview(self.timeLabelAndTotalTimeLabel)
        
        self.kuaiLabel = UILabel.init()
        self.kuaiLabel.textColor = UIColor(red: 225/255.0, green: 125/255.0, blue: 117/255.0, alpha: 1.0)
        self.kuaiLabel.font = UIFont.systemFont(ofSize: 12)
        self.kuaiLabel.textAlignment = .center
        self.backgroundView.addSubview(self.kuaiLabel)
        
        
    }

    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.backgroundView.frame = CGRect(x: (self.frame.size.width-150)/2.0, y: (self.frame.size.height-90)/2.0, width: 150, height: 90)
        self.kuaiImageView.frame = CGRect(x: (self.backgroundView.frame.size.width-30)/2.0, y: 6, width: 30, height: 30)
        self.timeLabelAndTotalTimeLabel.frame = CGRect(x: 0, y: self.kuaiImageView.frame.maxY+3, width: self.backgroundView.frame.size.width, height: 16)
        self.kuaiLabel.frame = CGRect(x: 0, y: self.timeLabelAndTotalTimeLabel.frame.maxY+5, width: self.backgroundView.frame.size.width, height: 21)
        
    }
    
    
   @objc public func kuai(_ duration:CGFloat, timeLabel:String, totalTimeLabel:String) {
        
        if duration > 0 {
            self.kuaiImageView.image = UIImage.init(named:"快进")
            self.kuaiLabel.text = String.init(format: "+%d秒", Int(duration))
        } else {
            self.kuaiImageView.image = UIImage.init(named:"倒退")
            self.kuaiLabel.text = String.init(format: "%d秒", Int(duration))
        }
      
        self.timeLabelAndTotalTimeLabel.text = timeLabel + " " + ("/") + " " + totalTimeLabel
     
    }
   
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
